const api = require("../../../utils/api")
const getwxphone = require("../../../utils/getwxphone")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    z: 1
  },
  back() {
    this.setData({
      z: 1,
      gx: !1,
      yh: !1
    })
  },
  tosf() {
    wx.navigateTo({
      url: '../out/sallclass/sallclass',
    })
  },

  gosearch() {
    var that = this;
    if (that.data.zljg && that.data.yrdw && that.data.zkzw && that.data.inputValueT) {
        var length = that.data.inputValueT.length;
        console.log(length)
        if(length==13){
          wx.request({ //发送请求
            url: 'https://zg99.offcn.com/index/chaxun/updateuser?actid=52445', //接收url
            data: {
              zkz: that.data.inputValueT,
              phone:wx.getStorageSync('52237phone'),
              zljg: that.data.zljg,
              yrdw: that.data.yrdw,
              zkzw: that.data.zkzw
            }, //接收参数
            success(res) {
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                var theJson = JSON.parse(jsonStr);
              }
              console.log(theJson)
            }
          })
          wx.request({ //发送请求
            url: 'https://zg99.offcn.com/index/chaxun/getfzinfo?actid=52445', //接收url
            data: {
              zljg: that.data.zljg,
              yrdw: that.data.yrdw,
              zkzw: that.data.zkzw
            }, //接收参数
            success(res) {
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                var theJson = JSON.parse(jsonStr);
              }
              console.log(theJson)
                that.setData({
                  lists: theJson.lists,
                  z: !1,
                  gx: 1,
                  yh: !1
                })
            }
          })
        }else{
          wx.showToast({
            title: '请输入正确准考证号',
            icon: 'none'
          })
        }
    }else{
      wx.showToast({
        title: '请输入完整信息',
        icon: 'none'
      })
    }
    
  },



  bindKeyInputT: function (e) {
    var _ = this
    _.setData({
      inputValueT: e.detail.value,
    })
    console.log(_.data.inputValueT)
  },


  getPhoneNumber(e) {
    var _ = this;
    const info = {
      area: wx.getStorageSync('area'),
      agent: wx.getStorageSync('agent'),
      page: wx.getStorageSync('page'),
      activeId: 42
    }
    getwxphone(e.detail.code, 52445, 'chaxun', info)
      .then(res => {
        console.log(res);
        this.gosearch()
      })
      .catch(err => {
        console.log(err);
      })
  },
  xz: function (e) {
    var _ = this;
    var flag = e.detail.value[0];
    if (flag == undefined) {
      flag = false
    } else {
      flag = true
    }
    _.setData({
      flag
    })
    console.log(_.data.flag)
  },
  xy: function (e) {
    var _ = this;
    wx.navigateTo({
      url: '../agreement/agreement',
    })
  },
  onLoad: function (options) {
    api.load(options)
    let phone = wx.getStorageSync('52237phone')
    if (phone) {
      this.setData({
        ifphone: 1
      })
    } else {
      this.setData({
        ifphone: !1
      })
    }
  },
  closeselect() {
    var that = this;
    that.setData({
      bindzljg: !1,
      bindyrdw: !1,
      bindzkzw: !1,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },


  
  //点击选择-招录机关zljg
  choisezljg() {
    var that = this;
    that.setData({
      bindzljg: 1,
    });
    that.zljg()
  },
  zljg() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=52445&callback=?', //接收url
      data: {
        level:'1',
        zljg:''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        if (theJson.status == 2) {
          list.push('暂无选项，请修改上级条件')
        } else {
          var a =  theJson.lists.length
          console.log(a)
          var arr =[]
          for(var i = 0;i < theJson.lists.length;i++){
            arr.push(theJson.lists[i].zljg)
          }
          var list = Array.from(new Set(arr))
          console.log(list)
        }
        that.setData({
          zljgList: list
        });
      }
    })
  },
  //点击选择-招录机关zljg
  setzljg(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zljg)
    that.setData({
      zljg: e.currentTarget.dataset.zljg,
      bindzljg: !1
    })
  },
  //点击选择-用人单位yrdw
  choiseMajor() {
    var that = this;
    if (that.data.edu) {
      that.setData({
        bindmajor: 1,
      })
      that.xuekemenlei()
    } else {
      wx.showToast({
        title: '请先选择学历',
        icon: 'none'
      })
    }
  },
  choiseyrdw() {
    var that = this;
    if (that.data.zljg) {
      that.setData({
        bindyrdw: 1,
      });
      that.yrdw()
    } else {
      wx.showToast({
        title: '请先选择招录机关',
        icon: 'none'
      })
    }
  },
  //2级联动-部门名称yrdw
  yrdw() {
    var that = this;
    console.log(that.data.zljg)
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=52445&callback=?', //接收url
      data: { level:'1',
        level:'2',
        grfiled: 'zljg',
        grtext: that.data.zljg
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        if (theJson.status == 2) {
          list.push('暂无选项，请修改上级条件')
        } else {
          var a =  theJson.lists.length
          console.log(a)
          var arr =[]
          for(var i = 0;i < theJson.lists.length;i++){
            arr.push(theJson.lists[i].yrdw)
          }
          var list = Array.from(new Set(arr))
          console.log(list)
        }
        that.setData({
          yrdwList: list
        });
      }
    })
  },
  //点击选择-部门名称yrdw
  setyrdw(e) {
    var that = this;
    console.log(e.currentTarget.dataset.yrdw)
    that.setData({
      yrdw: e.currentTarget.dataset.yrdw,
      bindyrdw: !1
    })
  },
  //点击选择-招录职位zkzw
  choisezkzw() {
    var that = this;
     if(that.data.zljg && that.data.yrdw){
        that.setData({
        bindzkzw: 1,
      });
      that.zkzw()
    } else {
        wx.showToast({
          title: '请先选择前两项',
          icon: 'none'
        })
    }
  },
  //4级联动-招录职位zkzw
  zkzw() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=52445&callback=?', //接收url
      data: { 
        level: '3',
        grfiled: 'yrdw',
        grtext: that.data.yrdw,
        onefiled: 'zljg',
        onetext: that.data.zljg
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        if (theJson.status == 2) {
          list.push('暂无选项，请修改上级条件')
        } else {
          var a =  theJson.lists.length
          console.log(a)
          var arr =[]
          for(var i = 0;i < theJson.lists.length;i++){
            arr.push(theJson.lists[i].zkzw)
          }
          var list = Array.from(new Set(arr))
          console.log(list)
        }
        that.setData({
          zkzwList: list
        });
      }
    })
    
  },
  //点击选择-招录职位zkzw
  setzkzw(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zkzw)
    that.setData({
      zkzw: e.currentTarget.dataset.zkzw,
      bindzkzw: !1
    })
  },
})